#include <linux/mman.h>
#include <linux/smp_lock.h>
#include <linux/pagemap.h>
+#include <linux/vmalloc.h>
#include <asm/hypervisor.h>
#include <asm/pgalloc.h>
} user_balloon_op_t;
/* END OF USER DEFINE */
-/* Dead entry written into ballon-owned entries in the PMT. */
+/* Dead entry written into balloon-owned entries in the PMT. */
#define DEAD 0xdeadbeef
static struct proc_dir_entry *balloon_pde;
return ptep;
}
-/* main function for relinquishing bit of memory */
+/* Main function for relinquishing memory. */
static unsigned long inflate_balloon(unsigned long num_pages)
{
unsigned long *parray;
unsigned long vaddr;
unsigned long i, j;
- parray = (unsigned long *)kmalloc(num_pages * sizeof(unsigned long),
- GFP_KERNEL);
+ parray = (unsigned long *)vmalloc(num_pages * sizeof(unsigned long));
+ if ( parray == NULL )
+ {
+ printk("inflate_balloon: Unable to vmalloc parray\n");
+ return 0;
+ }
+
currp = parray;
for ( i = 0; i < num_pages; i++ )
{
- /* Try to obtain a free page (has to be done with GFP_ATOMIC). */
- vaddr = __get_free_page(GFP_ATOMIC);
+ /* NB. Should be GFP_ATOMIC for a less aggressive inflation. */
+ vaddr = __get_free_page(GFP_KERNEL);
/* If allocation fails then free all reserved pages. */
if ( vaddr == 0 )
ret = num_pages;
cleanup:
- kfree(parray);
+ vfree(parray);
return ret;
}
-/* install new mem pages obtained by deflate_balloon. function walks
+/*
+ * Install new mem pages obtained by deflate_balloon. function walks
* phys->machine mapping table looking for DEAD entries and populates
* them.
*/
if ( phys_to_machine_mapping[i] == DEAD )
{
phys_to_machine_mapping[i] = *curr;
- queue_l1_entry_update(
- (pte_t *)((i << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE), i);
+ queue_machphys_update(*curr, i);
queue_l1_entry_update(
get_ptep((unsigned long)__va(i << PAGE_SHIFT)),
((*curr) << PAGE_SHIFT) | pgprot_val(PAGE_KERNEL));
}
}
- /* now, this is tricky (and will also change for machine addrs that
- * are mapped to not previously released addresses). we free pages
- * that were allocated by get_free_page (the mappings are different
- * now, of course).
- */
+ /*
+ * This is tricky (and will also change for machine addrs that
+ * are mapped to not previously released addresses). We free pages
+ * that were allocated by get_free_page (the mappings are different
+ * now, of course).
+ */
curr = parray;
for ( i = 0; i < num_installed; i++ )
{
return -EAGAIN;
}
- parray = (unsigned long *)kmalloc(num_pages * sizeof(unsigned long),
- GFP_KERNEL);
+ parray = (unsigned long *)vmalloc(num_pages * sizeof(unsigned long));
+ if ( parray == NULL )
+ {
+ printk("inflate_balloon: Unable to vmalloc parray\n");
+ return 0;
+ }
+
+ XEN_flush_page_update_queue();
ret = HYPERVISOR_dom_mem_op(MEMOP_increase_reservation,
parray, num_pages);
credit -= num_pages;
cleanup:
- kfree(parray);
+ vfree(parray);
return ret;
}
return sizeof(bop);
}
-/*
- * main balloon driver initialization function.
- */
static int __init init_module(void)
{
printk(KERN_ALERT "Starting Xen Balloon driver\n");
module_init(init_module);
module_exit(cleanup_module);
-
-